package com.zp.self.module.工具.json转换.json_json;

import com.google.common.collect.Sets;
import com.zp.self.module.工具.json转换.jsonUtil.JsonUtil;
import com.zp.self.module.工具.json转换.jsonUtil.ConmmonJsonUtil;
import org.json.JSONArray;

import java.io.IOException;

/**
 * @author ：by peng.zeng
 * @date ：Created 2021/9/3 15:05
 * @description ：整理
 */
public class Json2CsvOk_2合1_工况静态变量 {
    public static void main(String[] args) throws IOException {
        JSONArray mainJson = JsonUtil.getJson("C:\\Users\\peng.zeng\\Desktop\\DeviceAll_thingId_20220310.json");

        JSONArray otherJson_0 = JsonUtil.getJson("C:\\Users\\peng.zeng\\Desktop\\新系统工况2022-03-10-12-29.json");//新系统工况合并
        JsonUtil.multipleJsonMerge(mainJson, otherJson_0, "thingId","Pump_Operating_Time","Mileage","Delivered_Amount");

        JSONArray otherJson_1 = JsonUtil.getJson("C:\\Users\\peng.zeng\\Desktop\\旧系统工况2022-03-10-12-09.json");// 旧系统工况合并
        JsonUtil.multipleJsonMerge(mainJson, otherJson_1, "deviceId",new String[]{"Pump_Operating_Time_Adjustment_By","Pump_Operating_Time_Adjustment_On"
                ,"Mileage_Adjustment_By","Mileage_Adjustment_On"
                ,"Delivered_Amount_Adjustment_By","Delivered_Amount_Adjustment_On"},
                Sets.newHashSet("Delivered_Amount_Adjustment_On"));

        //合并json
//        String outPathStr="C:\\Users\\peng.zeng\\Desktop\\newDevice_info_工况_旧工况.json";
//        File file = new File(outPathStr);
//        FileUtils.writeStringToFile(file, mainJson.toString(), "utf-8", true);

        //转scv
        ConmmonJsonUtil.addFiled(mainJson,"Pump_Operating_Time_Adjustment_By","Mileage_Adjustment_By","Delivered_Amount_Adjustment_By",
                "Pump_Operating_Time","Mileage","Delivered_Amount");
        String outPathStr="C:\\Users\\peng.zeng\\Desktop\\分析_工况.csv";
        JsonUtil.json2csv(mainJson,outPathStr);
    }
}
